//==================================================================================
//		Dual Quad Board Program
//		file name : Key_Led_Control.C
//		version : 1.0
//		target device : w78e516(winbond)
//		target board : dual quad board
//		c compiler : Keil
//==================================================================================

void Key_Check(U8);
//void Serial_Key_Check();

//==================================================================================
//function	:
//param
//	
//
//key_group_num: the value is 0, 1, 2.
//==================================================================================
void Key_Check(U8 key_group_num)
{
	U8 i, _value, temp1;
	static U8 key_group = 0;
	U8 *ptr;

	if(key_group_num == 0)
		temp1 = 0x63;
	else if(key_group_num == 1)
		temp1 = 0x69;
//	else
//		temp1 = 0x2b;
				
	MDATA = temp1;
	chip_sel_LE = 1;
	chip_sel_LE = 0;
	KEY_OE = 0;
	_value = MDATA;
	KEY_OE = 1;
	MDATA = 0x6b;
	chip_sel_LE = 1;
	chip_sel_LE = 0;
		
	ptr = &key_scan_data;

	for(i=0;i<9;i++)
	{
		if(*ptr == _value)
		{
			_value = *(ptr+1);
			break;
		}	
		ptr += 2;
	}

	if((i >8)&&(_value != 0xff))
		return;
	if(_value == 0xff)						//... Key not push		
	{					
		if(key_group == key_group_num +1)
		{
			key_on_count = 0; 
			key_off_count++;
			if(key_off_count >2)
			{
				if((multi_function_in == ON) &&(long_key_in == OFF))
					key_code = key_value_backup;			
//				key_in = OFF;
				multi_function_in = OFF;
				long_key_in = OFF;
				long_key_timer = 0;	
				key_off_count = 0;
				key_value_backup = 0;
				key_value_backup1 = 0;
			}
		}
	}	
	else									//... Key push		
	{
		key_off_count = 0;
//		key_in = ON;
		key_group = key_group_num +1;
		key_on_count++;
		if(key_on_count > 2) 
		{
			key_on_count = 0;
/*			if((key_group_num == 0) &&((_value >4) &&(_value <9)))
			{
				long_key_timer++;
				key_value_backup = _value;
				multi_function_in = ON;

				if(zoom_mode_in == ON)
				{
					key_code = _value;
					return;
				}
				if((ch_control_on_off == OFF)&&(menu_on == OFF))
					key_code = key_value_backup +12;
			}*/	
			//for junan gongmao
			if((key_group_num == 0) &&((_value >3) &&(_value <9)))
			{
				long_key_timer++;
				key_value_backup = _value;
				multi_function_in = ON;

				if((_value >4) &&(_value<9))
				{
					if(zoom_mode_in == ON)
					{
						key_code = _value;
						return;
					}
					if((ch_control_on_off == OFF)&&(menu_on == OFF))
						key_code = key_value_backup +13;
				}
				else if((long_key_timer >50) &&(long_key_in == OFF))
				{
					long_key_timer = 50;
					multi_function_in = OFF;
					long_key_in = ON;
					key_code = key_value_backup +13;
				}
			}	
			else 
			{
				key_code = _value +key_group_num *8;
			}
			if(key_code == key_value_backup1)
				key_code = 0;
			else
				key_value_backup1 = key_code;
		}		
	}
}


